<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>珠峰架构师成长计划</title>
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">
</head>
<body>
<div class="nav">
    <div class="logo">
        
            珠峰架构师成长计划
        
    </div>
<ul><li><a href="../index.html">0.Async</a></li><li><a href="../html/0.editor.html">0.editor</a></li><li><a href="../html/0.module.html">0.module</a></li><li><a href="../html/1.ES2015.html">1.ES2015</a></li><li><a href="../html/2.Promise.html">2.Promise</a></li><li><a href="../html/3.Node.html">3.Node</a></li><li><a href="../html/4.NodeInstall.html">4.NodeInstall</a></li><li><a href="../html/5.REPL.html">5.REPL</a></li><li class="active"><a href="../html/6.NodeCore.html">6.NodeCore</a></li><li><a href="../html/7.module&NPM.html">7.module&NPM</a></li><li><a href="../html/8.Encoding.html">8.Encoding</a></li><li><a href="../html/9.Buffer.html">9.Buffer</a></li><li><a href="../html/10.fs.html">10.fs</a></li><li><a href="../html/11.Stream-1.html">11.Stream-1</a></li><li><a href="../html/11.Stream-2.html">11.Stream-2</a></li><li><a href="../html/11.Stream-3.html">11.Stream-3</a></li><li><a href="../html/11.Stream-4.html">11.Stream-4</a></li><li><a href="../html/12-Network-2.html">12-Network-2</a></li><li><a href="../html/12.NetWork-3.html">12.NetWork-3</a></li><li><a href="../html/12.Network-1.html">12.Network-1</a></li><li><a href="../html/13.tcp.html">13.tcp</a></li><li><a href="../html/14.http-1.html">14.http-1</a></li><li><a href="../html/14.http-2.html">14.http-2</a></li><li><a href="../html/15.compress.html">15.compress</a></li><li><a href="../html/16.crypto.html">16.crypto</a></li><li><a href="../html/17.process.html">17.process</a></li><li><a href="../html/18.yargs.html">18.yargs</a></li><li><a href="../html/19.cache.html">19.cache</a></li><li><a href="../html/20.action.html">20.action</a></li><li><a href="../html/21.https.html">21.https</a></li><li><a href="../html/22.cookie.html">22.cookie</a></li><li><a href="../html/23.session.html">23.session</a></li><li><a href="../html/24.express-1.html">24.express-1</a></li><li><a href="../html/24.express-2.html">24.express-2</a></li><li><a href="../html/24.express-3.html">24.express-3</a></li><li><a href="../html/24.express-4.html">24.express-4</a></li><li><a href="../html/25.koa-1.html">25.koa-1</a></li><li><a href="../html/26.webpack-1-basic.html">26.webpack-1-basic</a></li><li><a href="../html/26.webpack-2-optimize.html">26.webpack-2-optimize</a></li><li><a href="../html/26.webpack-3.tapable.html">26.webpack-3.tapable</a></li><li><a href="../html/26.webpack-4-AST.html">26.webpack-4-AST</a></li><li><a href="../html/26.webpack-5-source.html">26.webpack-5-source</a></li><li><a href="../html/26.webpack-6-loader.html">26.webpack-6-loader</a></li><li><a href="../html/26.webpack-7-plugin.html">26.webpack-7-plugin</a></li><li><a href="../html/26.webpack-8-hand.html">26.webpack-8-hand</a></li><li><a href="../html/27.react-1.html">27.react-1</a></li><li><a href="../html/27.react-2.html">27.react-2</a></li><li><a href="../html/27.react-3.html">27.react-3</a></li><li><a href="../html/27.react-4-immutable.html">27.react-4-immutable</a></li><li><a href="../html/27.react-5-react-dom-diff.html">27.react-5-react-dom-diff</a></li><li><a href="../html/27.react-6.html">27.react-6</a></li><li><a href="../html/28.react-mobx.html">28.react-mobx</a></li><li><a href="../html/28.redux-0.html">28.redux-0</a></li><li><a href="../html/28.redux-1.html">28.redux-1</a></li><li><a href="../html/28.redux-2-中间件.html">28.redux-2-中间件</a></li><li><a href="../html/28.redux-3-saga.html">28.redux-3-saga</a></li><li><a href="../html/28.redux-jwt-back.html">28.redux-jwt-back</a></li><li><a href="../html/28.redux-jwt-front.html">28.redux-jwt-front</a></li><li><a href="../html/29.mongodb-1.html">29.mongodb-1</a></li><li><a href="../html/29.mongodb-2.html">29.mongodb-2</a></li><li><a href="../html/29.mongodb-3.html">29.mongodb-3</a></li><li><a href="../html/29.mongodb-4.html">29.mongodb-4</a></li><li><a href="../html/29.mongodb-5.html">29.mongodb-5</a></li><li><a href="../html/29.mongodb-6.html">29.mongodb-6</a></li><li><a href="../html/30.cms-1-mysql.html">30.cms-1-mysql</a></li><li><a href="../html/30.cms-2-mysql.html">30.cms-2-mysql</a></li><li><a href="../html/30.cms-3-mysql.html">30.cms-3-mysql</a></li><li><a href="../html/30.cms-4-egg.html">30.cms-4-egg</a></li><li><a href="../html/30.cms-5-api.html">30.cms-5-api</a></li><li><a href="../html/30.cms-6-roadhog.html">30.cms-6-roadhog</a></li><li><a href="../html/30.cms-7-umi.html">30.cms-7-umi</a></li><li><a href="../html/30.cms-8-dva.html">30.cms-8-dva</a></li><li><a href="../html/30.cms-9-dva.html">30.cms-9-dva</a></li><li><a href="../html/30.cms-10-front.html">30.cms-10-front</a></li><li><a href="../html/30.cms-11-deploy.html">30.cms-11-deploy</a></li><li><a href="../html/33.redis.html">33.redis</a></li><li><a href="../html/34.unittest.html">34.unittest</a></li><li><a href="../html/35.jwt.html">35.jwt</a></li><li><a href="../html/36.websocket-1.html">36.websocket-1</a></li><li><a href="../html/36.websocket-2.html">36.websocket-2</a></li><li><a href="../html/38.chat-api-1.html">38.chat-api-1</a></li><li><a href="../html/38.chat-api-2.html">38.chat-api-2</a></li><li><a href="../html/38.chat-3.html">38.chat-3</a></li><li><a href="../html/38.chat-api-3.html">38.chat-api-3</a></li><li><a href="../html/38.chat.html">38.chat</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/38.chat2.html">38.chat2</a></li><li><a href="../html/39.crawl-0.html">39.crawl-0</a></li><li><a href="../html/39.crawl-1.html">39.crawl-1</a></li><li><a href="../html/39.crawl-2.html">39.crawl-2</a></li><li><a href="../html/40.deploy.html">40.deploy</a></li><li><a href="../html/41.safe.html">41.safe</a></li><li><a href="../html/42.test.html">42.test</a></li><li><a href="../html/43.nginx.html">43.nginx</a></li><li><a href="../html/44.enzyme.html">44.enzyme</a></li><li><a href="../html/45.docker.html">45.docker</a></li><li><a href="../html/46.elastic.html">46.elastic</a></li><li><a href="../html/47.oauth.html">47.oauth</a></li><li><a href="../html/48.wxpay.html">48.wxpay</a></li><li><a href="../html/49.nunjucks.html">49.nunjucks</a></li><li><a href="../html/50.ketang.html">50.ketang</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/51.typescript.html">51.typescript</a></li><li><a href="../html/52.UML.html">52.UML</a></li><li><a href="../html/53.design.html">53.design</a></li><li><a href="../html/index.html">index</a></li><li><a href="../html/54.linux.html">54.linux</a></li><li><a href="../html/55.yaml.html">55.yaml</a></li><li><a href="../html/50.ketang2.html">50.ketang2</a></li><li><a href="../html/56.ts.html">56.ts</a></li><li><a href="../html/57.ts_react.html">57.ts_react</a></li><li><a href="../html/58.react-ssr.html">58.react-ssr</a></li><li><a href="../html/59.react-ssr.html">59.react-ssr</a></li></ul></div>


<div class="warpper">

    <div class="page-toc">
        <ul><li><a href="#t01. 控制台">1. 控制台</a></li><li><a href="#t12. 全局作用域">2. 全局作用域</a></li><li><a href="#t23. 函数">3. 函数</a></li><li><a href="#t34. process">4. process</a><ul><li><a href="#t44.1 process对象">4.1 process对象</a></li><li><a href="#t54.2 process.nextTick & setImmediate">4.2 process.nextTick & setImmediate</a></li></ul></li><li><a href="#t65. EventEmitter">5. EventEmitter</a></li><li><a href="#t7util">util</a></li><li><a href="#t86. node断点调试">6. node断点调试</a></li></ul>
    </div>
    
    <div class="content markdown-body">
        <h2 id="t01. &#x63A7;&#x5236;&#x53F0;">1. &#x63A7;&#x5236;&#x53F0; <a href="#t01. &#x63A7;&#x5236;&#x53F0;"> # </a></h2>
<p>&#x5728;Node.js&#x4E2D;&#xFF0C;&#x4F7F;&#x7528;<code>console</code>&#x5BF9;&#x8C61;&#x4EE3;&#x8868;&#x63A7;&#x5236;&#x53F0;(&#x5728;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x4E2D;&#x8868;&#x73B0;&#x4E3A;&#x4E00;&#x4E2A;&#x64CD;&#x4F5C;&#x7CFB;&#x7EDF;&#x6307;&#x5B9A;&#x7684;&#x5B57;&#x7B26;&#x754C;&#x9762;&#xFF0C;&#x6BD4;&#x5982; Window&#x4E2D;&#x7684;&#x547D;&#x4EE4;&#x63D0;&#x793A;&#x7A97;&#x53E3;)&#x3002;</p>
<ul>
<li>console.log</li>
<li>console.info</li>
<li>console.error &#x91CD;&#x5B9A;&#x5411;&#x5230;&#x6587;&#x4EF6;</li>
<li>console.warn</li>
<li>console.dir</li>
<li>console.time</li>
<li>console.timeEnd</li>
<li>console.trace</li>
<li>console.assert</li>
</ul>
<h2 id="t12. &#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;">2. &#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF; <a href="#t12. &#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;"> # </a></h2>
<ul>
<li>&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;(global)&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x4E00;&#x4E9B;&#x4E0D;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x4EFB;&#x4F55;&#x6A21;&#x5757;&#x7684;&#x52A0;&#x8F7D;&#x5373;&#x53EF;&#x4F7F;&#x7528;&#x7684;&#x53D8;&#x91CF;&#x3001;&#x51FD;&#x6570;&#x6216;&#x7C7B;</li>
<li>&#x5B9A;&#x4E49;&#x5168;&#x5C40;&#x53D8;&#x91CF;&#x65F6;&#x53D8;&#x91CF;&#x4F1A;&#x6210;&#x4E3A;global&#x7684;&#x5C5E;&#x6027;&#x3002;</li>
<li>&#x6C38;&#x8FDC;&#x4E0D;&#x8981;&#x4E0D;&#x4F7F;&#x7528;var&#x5173;&#x952E;&#x5B57;&#x5B9A;&#x4E49;&#x53D8;&#x91CF;&#xFF0C;&#x4EE5;&#x514D;&#x6C61;&#x67D3;&#x5168;&#x5C40;&#x4F5C;&#x7528;&#x57DF;</li>
<li>setTimeout clearTimeout</li>
<li>setInterval clearInterval</li>
<li>unref&#x548C;ref</li>
</ul>
<pre><code>let test = function(){
  console.log(&apos;callback&apos;);
}
let timer = setInterval(test,1000);
timer.unref();
setTimeout(function(){
  timer.ref();
},3000)
</code></pre><h2 id="t23. &#x51FD;&#x6570;">3. &#x51FD;&#x6570; <a href="#t23. &#x51FD;&#x6570;"> # </a></h2>
<ul>
<li>require</li>
<li>&#x6A21;&#x5757;&#x52A0;&#x8F7D;&#x8FC7;&#x7A0B;</li>
<li>require.resolve</li>
<li>&#x6A21;&#x677F;&#x7F13;&#x5B58;(require.cache)</li>
<li>require.main</li>
<li>&#x6A21;&#x5757;&#x5BFC;&#x51FA;<pre><code>module.exports, require, module, filename, dirname
</code></pre></li>
</ul>
<h2 id="t34. process">4. process <a href="#t34. process"> # </a></h2>
<h3 id="t44.1 process&#x5BF9;&#x8C61;">4.1 process&#x5BF9;&#x8C61; <a href="#t44.1 process&#x5BF9;&#x8C61;"> # </a></h3>
<p>&#x5728;node.js&#x91CC;&#xFF0C;process &#x5BF9;&#x8C61;&#x4EE3;&#x8868;node.js&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#xFF0C;&#x53EF;&#x4EE5;&#x83B7;&#x53D6;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x7684;&#x7528;&#x6237;&#xFF0C;&#x8FD0;&#x884C;&#x73AF;&#x5883;&#x7B49;&#x5404;&#x79CD;&#x4FE1;&#x606F;</p>
<pre><code>process.argv.forEach(function(item){
  console.log(item);
});
process.on(&apos;exit&apos;,function(){
  console.log(&apos;clear&apos;);
});

process.on(&apos;uncaughtException&apos;,function(err){
  console.log(err);
})

console.log(process.memoryUsage());
console.log(process.cwd());
console.log(__dirname);
process.chdir(&apos;..&apos;);
console.log(process.cwd());
console.log(__dirname);

function err(){
 throw new Error(&apos;&#x62A5;&#x9519;&#x4E86;&apos;);
}
err();
</code></pre><h3 id="t54.2 process.nextTick &amp; setImmediate">4.2 process.nextTick &amp; setImmediate <a href="#t54.2 process.nextTick &amp; setImmediate"> # </a></h3>
<ul>
<li>process.nextTick()&#x65B9;&#x6CD5;&#x5C06; callback &#x6DFB;&#x52A0;&#x5230;&quot;next tick &#x961F;&#x5217;&quot;&#x3002; &#x4E00;&#x65E6;&#x5F53;&#x524D;&#x4E8B;&#x4EF6;&#x8F6E;&#x8BE2;&#x961F;&#x5217;&#x7684;&#x4EFB;&#x52A1;&#x5168;&#x90E8;&#x5B8C;&#x6210;&#xFF0C;&#x5728;next tick&#x961F;&#x5217;&#x4E2D;&#x7684;&#x6240;&#x6709;callbacks&#x4F1A;&#x88AB;&#x4F9D;&#x6B21;&#x8C03;&#x7528;&#x3002;</li>
<li>setImmediate&#x9884;&#x5B9A;&#x7ACB;&#x5373;&#x6267;&#x884C;&#x7684; callback&#xFF0C;&#x5B83;&#x662F;&#x5728; I/O &#x4E8B;&#x4EF6;&#x7684;&#x56DE;&#x8C03;&#x4E4B;&#x540E;&#x88AB;&#x89E6;&#x53D1;</li>
</ul>
<pre><code>setImmediate(function(){
  console.log(&apos;4&apos;);
});
setImmediate(function(){
  console.log(&apos;5&apos;);
});
process.nextTick(function(){
  console.log(&apos;1&apos;);
  process.nextTick(function(){
    console.log(&apos;2&apos;);
    process.nextTick(function(){
      console.log(&apos;3&apos;);
    });
  });
});

console.log(&apos;next&apos;);
</code></pre><h2 id="t65. EventEmitter">5. EventEmitter <a href="#t65. EventEmitter"> # </a></h2>
<p>&#x5728;Node.js&#x7684;&#x7528;&#x4E8E;&#x5B9E;&#x73B0;&#x5404;&#x79CD;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x7684;event&#x6A21;&#x5757;&#x4E2D;&#xFF0C;&#x5B9A;&#x4E49;&#x4E86;EventEmitter&#x7C7B;&#xFF0C;&#x6240;&#x4EE5;&#x53EF;&#x80FD;&#x89E6;&#x53D1;&#x4E8B;&#x4EF6;&#x7684;&#x5BF9;&#x8C61;&#x90FD;&#x662F;&#x4E00;&#x4E2A;&#x7EE7;&#x627F;&#x81EA;EventEmitter&#x7C7B;&#x7684;&#x5B50;&#x7C7B;&#x5B9E;&#x4F8B;&#x5BF9;&#x8C61;&#x3002;</p>
<table>
<thead>
<tr>
<th style="text-align:left">&#x65B9;&#x6CD5;&#x540D;&#x548C;&#x53C2;&#x6570;</th>
<th style="text-align:left">&#x63CF;&#x8FF0;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">addListener(event,listener)</td>
<td style="text-align:left">&#x5BF9;&#x6307;&#x5B9A;&#x4E8B;&#x4EF6;&#x7ED1;&#x5B9A;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">on(event,listener)</td>
<td style="text-align:left">&#x5BF9;&#x6307;&#x5B9A;&#x4E8B;&#x4EF6;&#x7ED1;&#x5B9A;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">once(event,listener)</td>
<td style="text-align:left">&#x5BF9;&#x6307;&#x5B9A;&#x4E8B;&#x4EF6;&#x6307;&#x5B9A;&#x53EA;&#x6267;&#x884C;&#x4E00;&#x6B21;&#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">removeListener(event,listener)</td>
<td style="text-align:left">&#x5BF9;&#x6307;&#x5B9A;&#x4E8B;&#x4EF6;&#x89E3;&#x9664;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">removeAllListeners([event])</td>
<td style="text-align:left">&#x5BF9;&#x6307;&#x5B9A;&#x4E8B;&#x4EF6;&#x89E3;&#x9664;&#x6240;&#x6709;&#x7684;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">setMaxListeners(n)</td>
<td style="text-align:left">&#x6307;&#x5B9A;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x51FD;&#x6570;&#x7684;&#x6700;&#x5927;&#x6570;&#x91CF;.n&#x4E3A;&#x6574;&#x6570;&#x503C;&#xFF0C;&#x4EE3;&#x8868;&#x6700;&#x5927;&#x7684;&#x53EF;&#x6307;&#x5B9A;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x51FD;&#x6570;&#x7684;&#x6570;&#x91CF;</td>
</tr>
<tr>
<td style="text-align:left">listeners(event)</td>
<td style="text-align:left">&#x83B7;&#x53D6;&#x6307;&#x5B9A;&#x4E8B;&#x4EF6;&#x7684;&#x6240;&#x6709;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">emit(event,[arg1],[arg2],[...])</td>
<td style="text-align:left">&#x624B;&#x5DE5;&#x89E6;&#x53D1;&#x6307;&#x5B9A;&#x4E8B;&#x4EF6;</td>
</tr>
</tbody>
</table>
<pre><code>let EventEmitter = require(&apos;./events&apos;);
let util = require(&apos;util&apos;);
util.inherits(Bell,EventEmitter);
function Bell(){
  EventEmitter.call(this);
}
let bell = new Bell();
bell.on(&apos;newListener&apos;,function(type,listener){
  console.log(`&#x5BF9; ${type}  &#x4E8B;&#x4EF6;&#x589E;&#x52A0;${listener}`);
});
bell.on(&apos;removeListener&apos;,function(type,listener){
  console.log(`&#x5BF9;${type} &#x4E8B;&#x4EF6;&#x5220;&#x9664;${listener}`);
});
function teacherIn(thing){
  console.log(`&#x8001;&#x5E08;&#x5E26;${thing}&#x8FDB;&#x6559;&#x5BA4;`);
}
function studentIn(thing){
  console.log(`&#x5B66;&#x751F;&#x5E26;${thing}&#x8FDB;&#x6559;&#x5BA4;`);
}
function masterIn(thing){
  console.log(`&#x6821;&#x957F;&#x5E26;${thing}&#x8FDB;&#x6559;&#x5BA4;`);
}
bell.on(&apos;&#x54CD;&apos;,teacherIn);
bell.on(&apos;&#x54CD;&apos;,studentIn);
bell.once(&apos;&#x54CD;&apos;,masterIn);
bell.emit(&apos;&#x54CD;&apos;,&apos;&#x4E66;&apos;);
console.log(&apos;==============&apos;);
bell.emit(&apos;&#x54CD;&apos;,&apos;&#x4E66;&apos;);
console.log(&apos;==============&apos;);
bell.removeAllListeners(&apos;&#x54CD;&apos;);
console.log(&apos;==============&apos;);
bell.emit(&apos;&#x54CD;&apos;,&apos;&#x4E66;&apos;);
</code></pre><pre><code>function EventEmitter(){
  this.events = {};//&#x4F1A;&#x628A;&#x6240;&#x6709;&#x7684;&#x4E8B;&#x4EF6;&#x76D1;&#x542C;&#x51FD;&#x6570;&#x653E;&#x5728;&#x8FD9;&#x4E2A;&#x5BF9;&#x8C61;&#x91CC;&#x4FDD;&#x5B58;
  //&#x6307;&#x5B9A;&#x7ED9;&#x4E00;&#x4E2A;&#x4E8B;&#x4EF6;&#x7C7B;&#x578B;&#x589E;&#x52A0;&#x7684;&#x76D1;&#x542C;&#x51FD;&#x6570;&#x6570;&#x91CF;&#x6700;&#x591A;&#x6709;&#x591A;&#x5C11;&#x4E2A;
  this._maxListeners = 10;
}
EventEmitter.prototype.setMaxListeners = function(maxListeners){
  this._maxListeners = maxListeners;
}
EventEmitter.prototype.listeners = function(event){
  return this.events[event];
}
//&#x7ED9;&#x6307;&#x5B9A;&#x7684;&#x4E8B;&#x4EF6;&#x7ED1;&#x5B9A;&#x4E8B;&#x4EF6;&#x5904;&#x7406;&#x51FD;&#x6570;&#xFF0C;1&#x53C2;&#x6570;&#x662F;&#x4E8B;&#x4EF6;&#x7C7B;&#x578B; 2&#x53C2;&#x6570;&#x662F;&#x4E8B;&#x4EF6;&#x76D1;&#x542C;&#x51FD;&#x6570;
EventEmitter.prototype.on = EventEmitter.prototype.addListener = function(type,listener){
  if(this.events[type]){
    this.events[type].push(listener);
    if(this._maxListeners!=0&amp;&amp;this.events[type].length&gt;this._maxListeners){
      console.error(`MaxListenersExceededWarning: Possible EventEmitter memory leak detected. ${this.events[type].length} ${type} listeners added. Use emitter.setMaxListeners() to increase limit`);
    }
  }else{
    //&#x5982;&#x679C;&#x4EE5;&#x524D;&#x6CA1;&#x6709;&#x6DFB;&#x52A0;&#x5230;&#x6B64;&#x4E8B;&#x4EF6;&#x7684;&#x76D1;&#x542C;&#x51FD;&#x6570;&#xFF0C;&#x5219;&#x8D4B;&#x4E00;&#x4E2A;&#x6570;&#x7EC4;
    this.events[type] = [listener];
  }
}
EventEmitter.prototype.once = function(type,listener){
  //&#x7528;&#x5B8C;&#x5373;&#x711A;
 let  wrapper = (...rest)=&gt;{
   listener.apply(this);//&#x5148;&#x8BA9;&#x539F;&#x59CB;&#x7684;&#x76D1;&#x542C;&#x51FD;&#x6570;&#x6267;&#x884C;
   this.removeListener(type,wrapper);
 }
 this.on(type,wrapper);
}
EventEmitter.prototype.removeListener = function(type,listener){
  if(this.events[type]){
    this.events[type] = this.events[type].filter(l=&gt;l!=listener)
  }
}
//&#x79FB;&#x9664;&#x67D0;&#x4E2A;&#x4E8B;&#x4EF6;&#x7684;&#x6240;&#x6709;&#x76D1;&#x542C;&#x51FD;&#x6570;
EventEmitter.prototype.removeAllListeners = function(type){
  delete this.events[type];
}
EventEmitter.prototype.emit = function(type,...rest){
  this.events[type]&amp;&amp;this.events[type].forEach(listener=&gt;listener.apply(this,rest));
}
module.exports = EventEmitter;
</code></pre><h2 id="t7util">util <a href="#t7util"> # </a></h2>
<pre><code>var util = require(&apos;util&apos;);
//util.inherit();
console.log(util.inspect({name:&apos;zfpx&apos;}));
console.log(util.isArray([]));
console.log(util.isRegExp(/\d/));
console.log(util.isDate(new Date()));
console.log(util.isError(new Error));
</code></pre><h2 id="t86. node&#x65AD;&#x70B9;&#x8C03;&#x8BD5;">6. node&#x65AD;&#x70B9;&#x8C03;&#x8BD5; <a href="#t86. node&#x65AD;&#x70B9;&#x8C03;&#x8BD5;"> # </a></h2>
<p>V8 &#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x5F3A;&#x5927;&#x7684;&#x8C03;&#x8BD5;&#x5668;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7; TCP &#x534F;&#x8BAE;&#x4ECE;&#x5916;&#x90E8;&#x8BBF;&#x95EE;&#x3002;Nodejs&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;&#x5185;&#x5EFA;&#x8C03;&#x8BD5;&#x5668;&#x6765;&#x5E2E;&#x52A9;&#x5F00;&#x53D1;&#x8005;&#x8C03;&#x8BD5;&#x5E94;&#x7528;&#x7A0B;&#x5E8F;&#x3002;&#x60F3;&#x8981;&#x5F00;&#x542F;&#x8C03;&#x8BD5;&#x5668;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x52A0;&#x5165;debugger&#x6807;&#x7B7E;&#xFF0C;&#x5F53;Nodejs&#x6267;&#x884C;&#x5230;debugger&#x6807;&#x7B7E;&#x65F6;&#x4F1A;&#x81EA;&#x52A8;&#x6682;&#x505C;&#xFF08;debugger&#x6807;&#x7B7E;&#x76F8;&#x5F53;&#x4E8E;&#x5728;&#x4EE3;&#x7801;&#x4E2D;&#x5F00;&#x542F;&#x4E00;&#x4E2A;&#x65AD;&#x70B9;&#xFF09;&#x3002;</p>
<pre><code>var a = &apos;a&apos;;
var b = &apos;b&apos;;

debugger;

var all = a + &apos; &apos; + b;
console.log(all);
</code></pre><table>
<thead>
<tr>
<th style="text-align:left">&#x547D;&#x4EE4;</th>
<th style="text-align:left">&#x7528;&#x9014;</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left">c</td>
<td style="text-align:left">&#x7EE7;&#x7EED;&#x6267;&#x884C;&#x5230;&#x4E0B;&#x4E00;&#x4E2A;&#x65AD;&#x70B9;&#x5904;</td>
</tr>
<tr>
<td style="text-align:left">next,n</td>
<td style="text-align:left">&#x5355;&#x6B65;&#x6267;&#x884C;</td>
</tr>
<tr>
<td style="text-align:left">step,s</td>
<td style="text-align:left">&#x5355;&#x6B65;&#x8FDB;&#x5165;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">out,o</td>
<td style="text-align:left">&#x9000;&#x51FA;&#x5F53;&#x524D;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td style="text-align:left">setBreakpoint(10),sb(10)</td>
<td style="text-align:left">&#x5728;&#x7B2C;10&#x884C;&#x8BBE;&#x7F6E;&#x65AD;&#x70B9;</td>
</tr>
<tr>
<td style="text-align:left">repl</td>
<td style="text-align:left">&#x6253;&#x5F00;&#x6C42;&#x503C;&#x73AF;&#x5883;&#xFF0C;ctrl_c&#x9000;&#x56DE;debug&#x6A21;&#x5F0F;</td>
</tr>
<tr>
<td style="text-align:left">watch(exp)</td>
<td style="text-align:left">&#x628A;&#x8868;&#x8FBE;&#x5F0F;&#x6DFB;&#x52A0;&#x76D1;&#x89C6;&#x5217;&#x8868;</td>
</tr>
<tr>
<td style="text-align:left">watchers</td>
<td style="text-align:left">&#x663E;&#x793A;&#x6240;&#x6709;&#x8868;&#x8FBE;&#x5F0F;&#x7684;&#x503C;</td>
</tr>
</tbody>
</table>
<p><a href="https://nodejs.org/api/debugger.html">debugger</a></p>

        <div class="copyright">Powered by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>. Dependence <a href="https://nodejs.org">Node.js</a> run.</div>
    </div>
    
</div>

<script src="https://cdn.bootcss.com/jquery/3.0.0/jquery.js"></script>
<script>
$('.warpper .page-toc ul ul li a').on('click',function(){
  $('.warpper .page-toc ul ul li a').removeClass('my-active')
  $(this).addClass('my-active')
})
  // if (!$('.understand-me').length) {
  //   var bar = $(window).height() - $('.navbar ').height() - $('.page-toc').position().top;
  //   var count = bar / 26 / 2;
  //   var barHeight = $('.page-toc').outerHeight();
  //   $('.page-toc li').eq(0).children('a').addClass('red');
  //   var arr = [];
  //   $("h1,h2,h3,h4,h5,h6").each(function () {
  //     arr.push($(this).position().top);
  //   });
  //   var timer
  //   function dark() {
  //     clearTimeout(timer)
  //      timer = setTimeout(function () {
  //      var top = Math.abs($('.page-toc > ul').position().top);
  //      var cur = $('.content').scrollTop();
  //      for (var i = arr.length; i >= 0; i--) {
  //        if (arr[i] <= cur) {
  //          break;
  //        }
  //      }
  //      if (i === -1) {
  //        i = 0;
  //      }
  //      $('.page-toc li a').removeClass('red');
  //      $('.page-toc li').eq(i).children('a').addClass('red');
  //      let height = $('.page-toc li').eq(i).position().top-$('.page-toc').height(); // 如果当前的offset出去了 回到中间可好？
  //      $('.page-toc').scrollTop(height+$('.page-toc').height()/2);
  //    },200)
  //   }

  //   $('.content').on('scroll', dark);
  // }
</script>
<style>

    /* ::-webkit-scrollbar{width:14px;}
    ::-webkit-scrollbar-track{background-color:transparent;}
    ::-webkit-scrollbar-thumb{background-color:transparent;}
    ::-webkit-scrollbar-thumb:hover {background-color:transparent}
    ::-webkit-scrollbar-thumb:active {background-color:transparent} */

    .page-toc > ul .red {
        background: #f3f3f3;
        z-index: 1;
        border-left: 3px solid #009a61;
        -webkit-transition: all .2s ease;
        transition: all .2s ease;
        color: #000
    }





</style>
</body>
</html>
